package logger

import "go.uber.org/zap"

// 适配器模式
type ZapLogger struct {
	l *zap.Logger
}

func NewzapLogger(l *zap.Logger) Logger {
	return &ZapLogger{l: l}
}

func (z *ZapLogger) Debug(key string, args ...Field) {
	z.l.Debug(key, toArgs(args)...)
}

func (z *ZapLogger) Info(key string, args ...Field) {
	z.l.Info(key, toArgs(args)...)
}

func (z *ZapLogger) Warn(key string, args ...Field) {
	z.l.Warn(key, toArgs(args)...)
}

func (z *ZapLogger) Error(key string, args ...Field) {
	z.l.Error(key, toArgs(args)...)
}

func toArgs(args []Field) []zap.Field {
	res := make([]zap.Field, 0, len(args))
	for _, arg := range args {
		res = append(res, zap.Any(arg.Key, arg.Val))
	}
	return res
}
